<template>
  <div>
    <Base
      ref="baseRef"
      :options="options"
      v-model:throwing-weight="throwingWeight"
      v-model:deliverMode="deliverMode"
      v-model:billingType="billingType"
      :data="data.channel"
      id="基本信息"
    />
    <Freight
      ref="freightRef"
      :options="options"
      :throwingWeight="throwingWeight"
      :billingType="billingType"
      :data="data.channel"
      id="运价信息"
    />
    <!-- <Attach
      v-show="deliverMode"
      ref="AttachRef"
      :options="options"
      :deliverMode="deliverMode"
      :data="attachData"
      id="附加费用信息"
    /> -->
  </div>
</template>
<script setup>
import { ElMessage } from 'element-plus'
import Base from './Base/index.vue'
import Freight from './Freight/index.vue'
import Attach from './Attach/index.vue'

const baseRef = ref()
const freightRef = ref()
// const AttachRef = ref()

const props = defineProps({
  data: { type: Object, default: () => ({}) },
  options: { type: Object, default: () => ({}) },
})
// const attachData = ref({})
// watch(() => props.data, val => {
//   if(val){
//     attachData.value = val
//   }
// },{
//   deep: true
// })
const throwingWeight = ref()
const deliverMode = ref()
const billingType = ref()

const submit = () => {
  return new Promise(async (resolve, reject) => {
    try {
      const { time = [], ...baseInfo } = await baseRef.value.formRef.submit()
      const { volumeWeight, discount, ...freightInfo } =
        await freightRef.value.submit()
      // const AttachInfo = await AttachRef.value.submit()
      resolve({
        start_time: time?.[0],
        end_time: time?.[1],
        ...baseInfo,
        ...freightInfo,
        // ...AttachInfo,
        ...discount,
        ...volumeWeight,
      })
    } catch (e) {
      ElMessage.warning('请检查基本资料填写')
      reject('baseInfo')
      console.error(e)
    }
  })
}

defineExpose({ submit })
</script>
